package com.yysjyr.logisticssystem.workbench.controller.emp;

import com.yysjyr.logisticssystem.common.ReturnObject;
import com.yysjyr.logisticssystem.common.contants.Contants;
import com.yysjyr.logisticssystem.settings.entity.User;
import com.yysjyr.logisticssystem.settings.service.UserService;
import com.yysjyr.logisticssystem.workbench.entity.Address;
import com.yysjyr.logisticssystem.workbench.service.AddressService;
import io.micrometer.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("address1")
@RequestMapping("/workbench/emp/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    @Autowired
    private UserService userService;

    @RequestMapping("getAddressByUsername")
    public ReturnObject getAddressByUsername(String username) {

        String userId = userService.queryUserIdByUsername(username);
        if (StringUtils.isEmpty(userId)) {
            return ReturnObject.NO("输入的用户名不存在!");
        }
        List<Address> addresses = addressService.queryListByUserId(userId);

        return ReturnObject.Ok(addresses);

    }
}
